package com.fm._3subscription;

import com.fm.util.ConnectionUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.util.Scanner;

/**
 * 要先创建ex1,然后绑定两个queue1和queue2
 * 因为发送到交换机没有指定routingKey，所以发送到所有队列
 */
public class SendMsg {
    public static void main(String[] args) throws Exception {
        System.out.println("请输⼊消息：");
        Scanner scanner = new Scanner(System.in);
        String msg = null;

        while (!"quit".equals(msg = scanner.nextLine())) {
            Connection connection = ConnectionUtil.getConnection();
            Channel channel = connection.createChannel();
            channel.basicPublish("ex1", "", null, msg.getBytes());
            System.out.println("发送：" + msg);
            channel.close();
            connection.close();
        }
    }
}